<template>
  <div class="topRightBlock">
    <div class="menu-list">
      <div
        v-for="(item, index) in menuList"
        :key="index"
        class="menu-label"
        :class="selectMenu === item.id ? 'colorSel' : 'colorWhite'"
        @click="selectPeriodClick(item.id)"
      >
        {{ item.value }}
      </div>
    </div>
    <i class="el-icon-s-tools" @click="styleSetting"></i>
    <div class="info-view">
      <el-badge is-dot class="item">
        <el-dropdown @command="handleCommand">
          <el-avatar
            shape="square"
            :size="size"
            :src="squareUrl"
            class="cur-porinter"
          ></el-avatar>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-badge>
      <div class="info-title">高新分局</div>
    </div>

    <el-dialog
      title="设置"
      :visible.sync="dialogVisible"
      width="478px"
      :before-close="handleClose"
    >
      <div class="dialogBox">
        <div>外观</div>
        <div class="content">
          <div
            :class="[
              'imgBox',
              {
                active: activeStyle === 'light',
              },
            ]"
            @click="activeStyle = 'light'"
          >
            <img
              src="../../../assets/img/light.png"
              width="136px"
              alt=""
              srcset=""
            />
            <span>浅色</span>
          </div>
          <div
            :class="[
              'imgBox',
              {
                active: activeStyle === 'dark',
              },
            ]"
            @click="activeStyle = 'dark'"
          >
            <img
              src="../../../assets/img/dark.png"
              width="136px"
              alt=""
              srcset=""
            />
            <span>深色</span>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="darkBtn" @click="dialogVisible = false"
          >取 消</el-button
        >
        <el-button type="primary" @click="ack">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { logout } from "@/api/login/login.js";
import Cookies from "js-cookie";

export default {
  components: {},
  props: {},
  data() {
    return {
      activeStyle: localStorage.style,
      dialogVisible: false,
      menuList: [
        { id: 1, value: "全景数据" },
        { id: 2, value: "统计查询" },
        { id: 5, value: "设备管理" },
        { id: 4, value: "住户分析" },
        { id: 3, value: "标签管理" },
      ],
      selectMenu: 1,
      size: "small",
      squareUrl: require("@/assets/img/login-head.png"),
    };
  },
  mounted() {},
  watch: {},
  methods: {
    ack() {
      localStorage.style = this.activeStyle;
      this.$emit("changeStyle");
      this.dialogVisible = false;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    styleSetting() {
      this.dialogVisible = true;
    },
    selectPeriodClick(val) {
      this.selectMenu = val;
      if (val === 2) {
        this.$router.push({ path: "/statisticsQuery/realTimeCapture" });
      } else if (val === 3) {
        this.$router.push({ path: "/labelManagement/labelPage" });
      } else if (val === 4) {
        this.$router.push({ path: "/residentManage/residentAnalyse" });
      } else if (val === 5) {
        this.$router.push({ path: "/deviceManage/devicePage" });
      }
    },
    handleCommand(command) {
      console.log(command);
      if (command === "logout") {
        logout().then(() => {
          Cookies.remove("token");
          Cookies.remove("user");
          window.location.href = "/login";
        });
      }
    },
  },
};
</script>

<style scoped lang="scss">
$marginTop: 15px;

.topRightBlock {
  width: 100%;
  height: 100%;
  color: #cdcfd0;
  // background: rgba(3, 10, 14, 0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 3;

  .menu-list {
    margin-top: $marginTop;
    display: flex;
    align-items: center;
    font-size: 18px;
    font-family: "SourceHanSans";

    .menu-label {
      margin-left: 55px;
      cursor: pointer;
    }
  }

  .info-view {
    margin-top: $marginTop;
    display: flex;
    align-items: center;

    .info-title {
      margin-left: 20px;
      font-size: 18px;
      font-family: "SourceHanSans";
    }

    .cur-porinter {
      cursor: pointer;
    }
  }
}

.colorSel {
  color: #ffffff;
  font-weight: bold;
  background: #456f9b;
  font-weight: 900;
  padding: 5px 12px;
  border-radius: 6px;
}

.colorWhite {
  // color: rgba(255, 255, 255, 0.8);
  color: #385065;
  font-size: 18px;
}

::v-deep {
  .el-badge__content,
  .el-progress {
    background-color: #4caf50;
    border: 2px solid #1f2935;
  }

  .el-badge__content.is-dot {
    height: 10px;
    width: 10px;
  }

  .el-avatar {
    background: #385065;
  }
}
</style>
<style lang="scss">
/* 整体背景色和圆角 */
.el-dropdown-menu {
  padding-top: 10px;
  background-color: #0a1a34 !important;
  border: 1px solid #f3f7f6 !important;
  border-radius: 5px;
  color: #f3f7f6 !important;
}

/* 下拉框定位 */
.el-popper {
  position: absolute !important;
  // top: 56px !important;
}

.el-popper[x-placement^="bottom"] {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 0px;
}

.el-dropdown-menu__item:not(:last-of-type) {
  border-bottom: 1px solid #00487f;
}

/* 消除小三角 */
.el-popper[x-placement^="bottom"] .popper__arrow {
  border: none;
}

.el-popper[x-placement^="bottom"] .popper__arrow::after {
  border: none;
}

.el-icon-s-tools {
  color: #01c2ff;
  cursor: pointer;
  font-size: 20px;
  margin-top: 12px;
}

.dialogBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;

  .content {
    display: flex;
    justify-content: center;
    width: 400px;
  }

  .imgBox {
    display: flex;
    flex-direction: column;
    text-align: center;
    margin-right: 20px;

    img {
      width: 136px;
      height: 76px;
      cursor: pointer;
    }
  }

  .active {
    img {
      border: 2px solid #308bfe;
      border-radius: 8px;
    }
  }
}

.el-dialog__header {
  padding: 0 20px;
  background: #0a1a34;
  padding-top: 16px;
  border-bottom: 0px solid #e5e5e5;

  .el-dialog__title {
    color: #fff;
  }
}

.el-dialog__headerbtn {
  display: none;
}

.el-dialog__body {
  background: #0a1a34;
  width: 478px !important;
  color: #fff;
}

.el-dialog__footer {
  background-color: #0a1a34;
  text-align: right;
  padding-right: 20px;
  box-sizing: border-box;
}
.el-dialog {
  margin-top: 30vh !important;
}
</style>
